Skip to content

Export StrictClickEvent type from StrictReactDOMProps#410

Closed
MoOx wants to merge 1 commit into
react:mainfrom
MoOx:patch-4
Closed

Export StrictClickEvent type from StrictReactDOMProps#410
MoOx wants to merge 1 commit into
react:mainfrom
MoOx:patch-4

Conversation

@MoOx

@MoOx MoOx commented Oct 2, 2025

Copy link
Copy Markdown
Contributor

This is useful when defining a callback, at least for typescript (otherwise, you need to redefined explicitly the type that match what a onClick could expect).

This is useful when defining a callback, at least for typescript (otherwise, you need to redefined explicitly the type that match what a onClick could expect)
@MoOx MoOx requested a review from necolas as a code owner October 2, 2025 17:32
@meta-cla meta-cla Bot added the cla signed label Oct 2, 2025
@MoOx

MoOx commented Oct 2, 2025

Copy link
Copy Markdown
Contributor Author

Well actually this is not enough. The type is not accessible anyway.
I will let this open to continue discussion about exported types.
Currently there is plenty of types I would be glad to import like this one, but they should be somehow reexported at the root of the package.
Is this something you will be ok with ?

Because otherwise, like said in the PR initial description, all the non-exported type at the package level need to be re-written.

@MoOx MoOx marked this pull request as draft October 2, 2025 17:36
@necolas

necolas commented Oct 2, 2025

Copy link
Copy Markdown
Contributor

We use Flow to get the prop types from the component

React.PropsOf<html.div>
React.PropsOf<html.div>['onClick']

@javascripter

javascripter commented Oct 3, 2025

Copy link
Copy Markdown
Contributor

For TypeScript you can do something like the below:

type StrictClickEventHandler = NonNullable<React.ComponentProps<typeof html.div>['onClick']>

// if you want to get the click event type itself
type StrictClickEvent =  Parameters<StrictClickEventHandler>[0]
// or 
type StrictClickEvent =  StrictClickEventHandler extends (event: infer E) => any ? E : never

React.ComponentProps works well as long as the prop types do not rely on generics (e.g. type Props<T> = { onFoo: (arg: T) => void }), meaning it works fine for RSD.

@necolas

necolas commented Oct 4, 2025

Copy link
Copy Markdown
Contributor

I think this type is a leftover from the early days when we had types like StrictHTMLElement. So it might be best to first FlowFixMe this event. Later we can properly type the event props to match what's expected on web

@MoOx

MoOx commented Oct 9, 2025

Copy link
Copy Markdown
Contributor Author

Yeah sorry I am used to have named types and always forgot that I can go deeper into a type with typescript.
Maybe we should document this somewhere, cause lots of projets have exported types for everything, while for RSD it's not the case, at least with TS.

@MoOx MoOx closed this Oct 9, 2025
@MoOx MoOx deleted the patch-4 branch October 9, 2025 08:10
@necolas

necolas commented Oct 9, 2025

Copy link
Copy Markdown
Contributor

Yeah that's a good idea!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants